package com.qfmy.web.config;

import lombok.Data;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author: 廖志伟
 * @date: 2024-11-28
 * @description: Redis配置类
 */
@SuppressWarnings("all")
@Configuration
@Data
public class RedisConfig {
    /**
     * redis序列化
     */
    @Bean
    public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
        RedisTemplate<String,Object> redisTemplate=new RedisTemplate<>();
        redisTemplate.setConnectionFactory(factory);
        //创建序列化容器
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        //设置key的序列化器
        redisTemplate.setKeySerializer(stringRedisSerializer);
//        //设置value的序列化器
//        redisTemplate.setValueSerializer(stringRedisSerializer);
        return redisTemplate;
    }
}